package com.translate.web.config;

import java.io.IOException;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

/**
 * 布尔值序列化器
 */
public class BooleanSerializer extends JsonSerializer<Boolean> {

	/**
	 * 序列化
	 *
	 * @param value    值
	 * @param gen      生成器
	 * @param provider 序列化提供者
	 * @throws IOException IO异常
	 */
	@Override
	public void serialize(Boolean value, JsonGenerator gen, SerializerProvider provider) throws IOException {
		if (value != null) {
			gen.writeString(value.toString());
		} else {
			gen.writeString(StringUtils.EMPTY);
		}
	}
}
